﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FrameWork.Source.Object_Classes;
using Microsoft.Xna.Framework;
using FrameWork.Source.Animation_Classes;
using FrameWork.Source.Texture;
using FrameWork.Source.Resource_Manager;
using Boomer.Source.Character;
using Boomer.Source.TiledMap;
using FrameWork.Source.Global_variables;

namespace Boomer.Source.MapItem
{
    class CMapItem : CAnimatedObject
    {
        public enum TYPE
        {
            BOOMSTR = 0 ,
            BOOMNUM = 1 ,
            MOVSPEED = 2
        }
        private Vector2 mapPos;
        private TYPE type;

        public CMapItem()
            : base()
        {

        }

        public override void init()
        {
            CAnimation[] pAnim;
            pAnim = new CAnimation[3];

            pAnim[0] = new CAnimation();
            pAnim[0].createAnimation("Boom Str", 0, 0, 0, 1.0f);

            pAnim[1] = new CAnimation();
            pAnim[1].createAnimation("Boom Number", 1, 1, 1, 1.0f);

            pAnim[2] = new CAnimation();
            pAnim[2].createAnimation("Movement Speed", 2, 2, 2, 1.0f);

            CTexture image = CResourceManager.getInstance().getImage((int)CResourceManager.IMG_MAIN.MAPITEM);

            this.loadSprite(image, 3, 3, 40, 48, pAnim);

            base.init();
        }

        public void setType(TYPE type)
        {
            this.type = (TYPE)type;
            if (type == CMapItem.TYPE.BOOMSTR)
            {
                this.changeAnimation("Boom Str");
            }
            if (type == CMapItem.TYPE.BOOMNUM)
            {
                this.changeAnimation("Boom Number");
            }
            if (type == CMapItem.TYPE.MOVSPEED)
            {
                this.changeAnimation("Movement Speed");
            }
        }

        public override void update(float deltaTime)
        {
            
            base.update(deltaTime);
        }

        public override void draw()
        {
            base.draw();
        }

        public override bool Collision(ref CObject pObj)
        {
            if (this.getBoundBox().Intersects(pObj.getBoundBox()))
            {
                this.m_isAlive = false;
                if (pObj.Tag == FrameWork.Tag_Manager.TagManager.TAGGED.Player || pObj.Tag == FrameWork.Tag_Manager.TagManager.TAGGED.Enemy)
                {
                    if (CGLOBAL.g_isPlayingSound)
                        Sound_Manager.SoundManager.getInstance().pickItem.Play();
                    if (type == TYPE.BOOMSTR)
                    {
                        ((CCharacter)pObj).boomStr += 1;
                    }
                    else if (type == TYPE.BOOMNUM)
                    {
                        ((CCharacter)pObj).numBoom += 1;
                    }
                    else if (type == TYPE.MOVSPEED)
                    {
                        ((CCharacter)pObj).speed += 50;
                        if (((CCharacter)pObj).speed >= ((CCharacter)pObj).maxSpeed)
                        {
                            ((CCharacter)pObj).speed = ((CCharacter)pObj).maxSpeed;
                        }
                    }
                }
            }
            return base.Collision(ref pObj);
        }
    }
}
